// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env:'mupp-5gs2863z7cf6873f'
})

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const db=cloud.database()
    const shopComment=db.collection('shopComment')
    let openid=wxContext.OPENID
    let {nickName,avatarUrl,content,_id}=event
    //添加评论
    console.log('event',event)
    let res=await shopComment.add({
        data:{
            nickName,time:db.serverDate(),avatarUrl,content,zan:[],openid,shop_id:_id
        }
    })
    console.log('添加结果',res)
    let result=res.errMsg
    if(result.indexOf('ok')){
        result=true
    }else{
        result=false
    }
    
    return {
        result
    }
}